﻿//-----------------------------------------------------------------------
// <copyright file="ComponentLogger.cs" author="Artak Mkrtchyan">
//     Creative Commons - GNU General Public License (http://creativecommons.org/licenses/GPL/2.0/
// </copyright>
// <author>Artak Mkrtchyan</author>
// <email>mkArtak@gmail.com</email>
// <date>08 Jun 2013</date>
//-----------------------------------------------------------------------

using System;

namespace ConsoleHoster.Common.Utilities
{
	/// <summary>
	/// Represents a logger that decorates each logged message with a component name
	/// </summary>
	public class ComponentLogger : ILogger
	{
		internal const string DecoratedMessagePattern = "Component: '{0}'\t{1}";

		private readonly ILogger logger;
		private readonly string componentName;

		public ComponentLogger(string argComponentName, ILogger argLogger)
		{
			if (String.IsNullOrWhiteSpace(argComponentName))
			{
				throw new ArgumentException("Invalid component name");
			}

			this.componentName = argComponentName;
            this.logger = argLogger ?? EmptyLogger.Instance;
		}

		public void LogError(string argFormat, params string[] args)
		{
			this.logger.LogError(DecoratedMessagePattern, this.componentName, StringUtilities.Format(argFormat, args));
		}

		public void LogMessage(string argFormat, params string[] args)
		{
			this.logger.LogMessage(DecoratedMessagePattern, this.componentName, StringUtilities.Format(argFormat, args));
		}

		public void LogWarning(string argFormat, params string[] args)
		{
			this.logger.LogWarning(DecoratedMessagePattern, this.componentName, StringUtilities.Format(argFormat, args));
		}

		public void Dispose()
		{
			this.logger.Dispose();
		}
	}
}
